home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / nan_news / toolkit / wda.prg < prev    next >
Text File  |  1991-08-15  |  3KB  |  86 lines

  1. /*
  2.  * File......: WDA.PRG
  3.  * Author....: Eric Splaver
  4.  * Date......: $Date:   15 Aug 1991 23:04:34  $
  5.  * Revision..: $Revision:   1.1  $
  6.  * Log file..: $Logfile:   E:/nanfor/src/wda.prv  $
  7.  * 
  8.  * This is an original work by Eric Splaver and is placed in the
  9.  * public domain.
  10.  *
  11.  * Modification history:
  12.  * ---------------------
  13.  *
  14.  * $Log:   E:/nanfor/src/wda.prv  $
  15.  * 
  16.  *    Rev 1.1   15 Aug 1991 23:04:34   GLENN
  17.  * Forest Belt proofread/edited/cleaned up doc
  18.  * 
  19.  *    Rev 1.0   14 Jun 1991 04:25:46   GLENN
  20.  * Initial revision.
  21.  *
  22.  */
  23.  
  24.  
  25. /*  $DOC$
  26.  *  $FUNCNAME$
  27.  *     FT_ADDWKDY()
  28.  *  $CATEGORY$
  29.  *     Date/Time
  30.  *  $ONELINER$
  31.  *     Return true number of days to add given number of workdays
  32.  *  $SYNTAX$
  33.  *     FT_ADDWKDY( <dStart>, <nWorkDays> ) -> nTrueDays
  34.  *  $ARGUMENTS$
  35.  *     <dStart> = date to start adding from
  36.  *     <nWorkDays> = number of workdays to add
  37.  *  $RETURNS$
  38.  *     <nTrueDays> = Number of actual days to add to <dStart> in
  39.  *                   order to add the required <nWorkDays>
  40.  *  $DESCRIPTION$
  41.  *      Let's say you are given the problem:
  42.  *
  43.  *         "All invoices are due 10 working days from the date they
  44.  *         are printed.  Please display the due date on the invoice."
  45.  *
  46.  *      When is the due date?  Assuming you are printing the invoices
  47.  *      today, your answer is:
  48.  *
  49.  *           dDueDate := DATE() + ft_addWkDay( DATE(), 10 )
  50.  *
  51.  *      A work day is defined as Monday through Friday.  Unfortunately
  52.  *      this routine does _not_ account for holidays.     
  53.  *      
  54.  *      This documentation was written by Glenn Scott so if it's wrong,
  55.  *      blame him.
  56.  *
  57.  *  $EXAMPLES$
  58.  *      // Postdate 5 working days from the first of January
  59.  *      dPost := CTOD("01/01/91") 
  60.  *      dPost += FT_ADDWKDY( dPost, 5 )   // returns 7 true days
  61.  *      ? dPost                          //  01/08/91
  62.  *      
  63.  *  $SEEALSO$
  64.  *      FT_WORKDAYS()
  65.  *  $END$
  66.  */
  67.  
  68. #ifdef FT_TEST
  69.   function main( cDate, cDays )
  70.      local nDays := ft_addWkDy( ctod(cDate), val(cDays) ) 
  71.      qout( "Num days to add: " + str( nDays ) )
  72.      qout( "New date:        " + dtoc( ctod( cDate ) + nDays ) )
  73.      return nil
  74. #endif
  75.  
  76.      
  77. FUNCTION ft_addWkDy( dStart, nDys )
  78.     LOCAL nDc  := dow( dStart )
  79.     RETURN ( iif( nDc == 7,                                                        ;
  80.             (nDys-1)      % 5 + 7 * int( (nDys-1)      / 5 ) + 2,         ;
  81.             (nDys+nDc-2)  % 5 + 7 * int( (nDys+nDc-2)  / 5 ) + 2  - nDc   ;
  82.                 )                                                                   ;
  83.             )
  84.  
  85.  
  86.